--[[-----------------------------------------------------------
	Init the game, call all needed scripts in this file
	
	Setups the camera, loads the current scene, etc.
	
	NOTE: This file is called by StartGame() function in the
	menu_init.lua file.
--]]-----------------------------------------------------------

-- Initialize all functions for triggers
dofile( "Entity_Triggers.lua" );
dofile( "Tile_Triggers.lua" );

-- Load the first mission
console.Exec( "map_change maps/map01.map" );

-- Change to the ingame state
gameState.PushState( "InGameState" );
dofile( "world_init.lua" );
dofile( "Camera.lua" );

--------------------------------------------------------------------------
--	In Game States HUD
--------------------------------------------------------------------------

buttonCreateEntity	= GUI_Button:new("buttonCreateEntity","");
buttonCreateEntity:SetSize( 110, 30 );
buttonCreateEntity:SetLocation( 10, 540 );
buttonCreateEntity:SetBackgroundColor( 0.09, 0.19, 0.08 );
buttonCreateEntity:SetAlpha( 0.9 );
buttonCreateEntity:SetForegroundColor( 0,0,0 );
buttonCreateEntity:SetText( "Spawn Entity");
buttonCreateEntity:SetOnClick( "CreateEntity" );
buttonCreateEntity:SetVisible( 1 );

buttonActivateCamera2	= GUI_Button:new("buttonActivateCamera2","");
buttonActivateCamera2:SetSize( 130, 30 );
buttonActivateCamera2:SetLocation( 130, 540 );
buttonActivateCamera2:SetBackgroundColor( 0.09, 0.19, 0.08 );
buttonActivateCamera2:SetAlpha( 0.9 );
buttonActivateCamera2:SetForegroundColor( 0,0,0 );
buttonActivateCamera2:SetText( "Toggle Camera 2");
buttonActivateCamera2:SetOnClick( "ActivateCamera2" );
buttonActivateCamera2:SetVisible( 1 );


function CreateEntity()
	entity.Create( "guard5" );
end

function ActivateCamera2()
	cameraActive = camera.IsActive( SECONDARY_CAMERA );
	if cameraActive == TRUE
	then
		camera.Activate( SECONDARY_CAMERA, FALSE );
	else
		camera.Activate( SECONDARY_CAMERA, TRUE );
		camera.Attach( SECONDARY_CAMERA, "The follower" );
	end
end

--[[ 
	Call this function when leaving the in game state
--]]
function FinishInGameState()
	buttonCreateEntity:Destroy(); -- all hud objects delete
	buttonActivateCamera2:Destroy();
	gameState.PopState(0);
end